package com.ruoyi.common.core.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.FileObject;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Transient;

import java.util.ArrayList;
import java.util.List;

/**
 * 部门表 sys_dept
 * 
 * @author ruoyi
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
@Accessors(chain = true)
@TableName(value = "sys_dept", autoResultMap = true)
@ToString
public class SysDept extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /** 组织ID */
    @ApiModelProperty("组织ID")
    @TableId(type = IdType.ASSIGN_ID)
    @JsonProperty("id")
    private Long deptId;

    @ApiModelProperty("父组织ID")
    private Long parentId;

    /** 祖级列表 */
    private String ancestors;

    @ApiModelProperty("组织名称")
    @Excel(name = "所属公司", width = 30, sort = 1)
    private String deptName;

    @ApiModelProperty("组织简称")
    @Excel(name = "公司简称", width = 30, sort = 2)
    private String shortName;

    /** 显示顺序 */
    private Integer orderNum;

    @ApiModelProperty("负责人")
    private String leader;

    @ApiModelProperty("联系电话")
    private String phone;

    /** 邮箱 */
    private String email;

    /** 图片 */
    @ApiModelProperty("组织图片")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<FileObject> picture;

    /** 类型(0公司 1节点 2车辆 3人员) */
    private Integer type;

    @ApiModelProperty("组织地址")
    @Excel(name = "公司地址", width = 50, sort = 4)
    private String address;

    /** 组织状态:0正常,1停用 */
    private String status;

    /** 删除标志（0代表存在 2代表删除） */
    private String delFlag;

    /** 父组织名称 */
    @TableField(exist = false)
    @Transient
    private String parentName;
    
    /** 子组织 */
    @TableField(exist = false)
    private List<SysDept> children = new ArrayList<SysDept>();
    /** 总设备数 **/
    @TableField(exist = false)
    @Transient
    @Excel(name = "设备总数", sort = 3)
    private Integer vehicleCount = 0;

    public String getShortName() {
        return StringUtils.isEmpty(shortName) ? deptName : shortName;
    }
}
